package gotnames.dm;

import javax.jdo.PersistenceManager;

/**
 * Extension of {@link FindOrCreate} which calls {@link #setValues(Object)} if the object
 * is already present to update it with the current values.
 */
public abstract class UpdateOrCreate<X> extends FindOrCreate<X> {

	/** See {@link FindOrCreate#FindOrCreate(PersistenceManager, Class)} */
	public UpdateOrCreate(PersistenceManager pm, Class<X> clazz) {
		super(pm, clazz);
	}
	
	@Override public PersistedEntityValue<X> go() {
		PersistedEntityValue<X> pe = super.go();
		if (!pe.isNew())
			setValues(pe.getEntityValue());
		return pe;
	}

}
